AWS SES

  • AWS

    1.Account

    go to https://portal.aws.amazon.com/billing/signup#/start

    2. Add a new domain

    Go here: https://eu-west-1.console.aws.amazon.com/ses/home?region=eu-west-1/verified-senders-domain

    3. Add an email address

    https://eu-west-1.console.aws.amazon.com/ses/home?region=eu-west-1#verified-senders-email:

    4. User and IAM

    Go here : https://console.aws.amazon.com/iam/home?region=eu-west-1#/users

    Enter a name for your user, eg “domain_SES” and tick “Programmatic access”. Click on “Next”.

    On the next screen click on “Attach existing policies directly” and search for the “AmazonSESFullAccess” policy:

    Tick the line and click “Next”.Click again “Next” (you can add tags if you want) and then click “Create User”.

    You will get key and secret

  • Configure the Laravel

    1.installing the AWS SDK for PHP

    
                        composer require aws/aws-sdk-php
    

    2. In config/services.php,

    
                    'ses' => [
        'key' => env('SES_KEY'),
        'secret' => env('SES_KEY_SECRET'),
        'region' => env('SES_REGION'),
    ],
    
    

    3. .env

    
                            MAIL_MAILER=ses
                AWS_ACCESS_KEY_ID=eqweqwe
                AWS_SECRET_ACCESS_KEY=qffU0C2nFA2/qweqweqweqweqwe+Iv3TaTFx
                AWS_DEFAULT_REGION=ap-south-1
                MAIL_FROM_EMAIL=info@gmail.in
    
                

    4. create mail class

    app/Mail/EnquiryMail.php

    
    
                    
    
                    namespace App\Mail;
                    use App\Models\Customer;
                    use Illuminate\Bus\Queueable;
                    use Illuminate\Mail\Mailable;
                    use Illuminate\Queue\SerializesModels;
                    use Illuminate\Contracts\Queue\ShouldQueue;
    
                    class EnquiryMail extends Mailable
                    {
                        use Queueable, SerializesModels;
                        
                        public $email_content;
                        
                        /**
                        * Create a new message instance.
                        *
                        * @return  void
                        */
                        public function __construct($email_content=[])
                        {
                            $this->email_content =$email_content;
                            
                        }
                        /**
                        * Build the message.
                        *
                        * @return  $this
                        */
                        public function build()
                        {
                             return $this->from(env('MAIL_FROM_EMAIL'))->subject("Enquiry from kanadikavu.com")->view('emails.enquiry',$this->email_content);
                        }
                    }
    
    
    
    
    
            

    5. Attach file

    
            return $this->from(env('MAIL_FROM_ADDRESS'))->subject($this->data['subject'])->view($this->data['template'])->with($this->data)->attach($this->data['attached_file']);
                

    4. in controller

    
                    use Illuminate\Support\Facades\Mail;
                    use App\Mail\EnquiryMail;
    
    
    
                    .... 
                    $mail=Mail::to("manojvijayan@jaivamlife.com")->send(new EnquiryMail($input));